<?php

session_start();
include "otamu_config.php";

?>
        <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
        <table border="0">
         <tr><td colspan=2><h1>Login</h1></td></tr>
         <tr><td>Username:</td><td>
         <input type="text" name="username" maxlength="40">
         </td></tr>
         <tr><td>Password:</td><td>
         <input type="password" name="pass" maxlength="50">
         </td></tr>
         <tr><td colspan="2" align="right">
         <input type="submit" name="submit" value="Login">
         </td></tr>
        </table>
        </form>

<?php

//if the login form is submitted

if (isset($_POST['submit'])) { // if form has been submitted
        // makes sure they filled it in

        if(!$_POST['username'] | !$_POST['pass']) {
                die('You did not fill in a required field.');
        }

        // checks it against the database
        $_POST['pass'] = stripslashes($_POST['pass']);
        $_POST['pass'] = md5($_POST['pass']);

        $check = pg_query("SELECT * FROM pengguna WHERE username = '".$_POST['username']."' AND passwd = '".$_POST['pass']."'");

        $check2 = pg_num_rows($check);
        if ($check2 == 0) {
                die('Username or password not matched.');
        }
        else
        {
                // if login is ok then we add a cookie

                $_POST['username'] = stripslashes($_POST['username']);

                session_register(ID_my_site);
                session_register(Key_my_site);

                $_SESSION['ID_my_site']=$_POST['username'];
                $_SESSION['Key_my_site']=$_POST['pass'];

                //then redirect them to the members area
                //header("Location: ");
        }
}
 

?>
